package cn.fl.institution.controller;

import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.*;
import cn.cmm.cache.framework.constant.CacheConstant;
import cn.cmm.cache.framework.service.ICacheService;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.service.ICstNpBscInfoService;
import cn.fl.customer.vo.CstNpBscInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.institution.api.IJxflInsApiService;
import cn.fl.project.api.IPrjCstAccInfoApiService;
import cn.fl.project.condition.PrjCstAccInfoQueryCondition;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.dto.PrjCstAccInfoDTO;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjCstAccInfoService;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjCstAccInfoVO;
import cn.fl.system.constant.SysInsCfgInfoConstant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import fl.constant.facade.framework.constant.SystemConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * @Description: 项目基础信息表 控制层 江西金租
 */
@Controller
@RequestMapping("/institution/jxfl")
public class PrjBscInfoInsJXFLController {
    private static final Logger logger = LoggerFactory.getLogger(PrjBscInfoInsJXFLController.class);

    @Autowired
    private IPrjBscInfoService prjBscInfoService; // 项目基础信息表

    @Autowired
    private IPrjCstAccInfoApiService prjCstAccInfoApiService; // 项目客户账户信息表

    @Autowired
    private ICstBscInfoService cstBscInfoService; // 客户基础信息

    @Autowired
    private ICstNpBscInfoService cstNpBscInfoService; // 自然人信息

    @Autowired
    private IPrjCstAccInfoService prjCstAccInfoService;//项目客户基础信息表

    @Autowired
    private IJxflInsApiService jxflInsApiService;

    @Autowired
    private ICacheService cacheService;

    /**
     * 获取验证码-广州银联绑卡验证码
     */
    @RequestMapping(value = "/getVerificationCodeGZYL.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object getVerificationCodeGZYL (Long prjId,PrjCstAccInfoQueryCondition prjCstAccInfoQC) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "四要素校验通过");
        BaseLogUtils.info(logger, "getVerificationCodeGZYL", "江西金租获取广州银联验证码 四要素信息： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));

        try{
            PrjCstAccInfoQueryCondition prjCstAccInfoQueryCondition = new PrjCstAccInfoQueryCondition();
            prjCstAccInfoQueryCondition.setPrjId(prjId);
            prjCstAccInfoQueryCondition.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfoQueryCondition.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_JXFL);

            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfoQueryCondition);
            // PrjCstAccInfoVO prjCstAccInfo = this.prjCstAccInfoService.selectByPrjId(prjId);
            BaseLogUtils.info(logger, "getVerificationCodeGZYL", "江西金租获取广州银联验证码 项目基本信息： prjBscInfoVO = " + JSONObject.toJSONString(prjCstAccInfoVOS));
            if(CollectionUtils.isEmpty(prjCstAccInfoVOS)){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("请先保存项目客户信息");
                return result;
            }
            // 四要素验证
            PrjCstAccInfoVO prjCstAccInfoVO = prjCstAccInfoVOS.get(0);
            if(null == prjCstAccInfoVO.getChkRstCd() || Integer.valueOf(prjCstAccInfoVO.getChkRstCd()) != BaseConstant.IS_YESNO_YES) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("四要素信息有误，请修改");
                return result;
            }
            if (null == prjCstAccInfoVO.getBankCardTypeCd() || "1".equals(prjCstAccInfoVO.getBankCardTypeCd())){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("不支持此类银行卡，请更换为借记卡");
                return result;
            }
            // 发送验证码
            DataResultDTO dataResultDTO = this.jxflInsApiService.getVerificationCodeGZYL(String.valueOf(prjId));
            if(dataResultDTO!=null){
                if(BaseConstant.IS_YESNO_YES_NM.equals(dataResultDTO.getCode())){
                    result.setSuccess(BaseConstant.IS_YESNO_YES);
                    result.setInfo(dataResultDTO.getInfo());
                }else{
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo(dataResultDTO.getInfo());
                }
                result.setData(dataResultDTO.getData()); // rstCode
            }else{
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("广州银联验证码获取失败，请重新尝试；");
            }
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.error(logger, "getVerificationCodeGZYL", "江西金租获取广州银联验证码失败 " + ex.getMessage());
            ex.printStackTrace();
        }
        catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("获取广州银联验证码失败!");
            BaseLogUtils.error(logger, "getVerificationCodeGZYL", "江西金租获取广州银联验证码失败 " + ex.getMessage());
            ex.printStackTrace();
        }
        return result;
    }

    /**
     * 获取验证码-易宝绑卡验证码
     */
    @RequestMapping(value = "/getVerificationCodeYB.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object getVerificationCodeYB (Long prjId,PrjCstAccInfoQueryCondition prjCstAccInfoQC) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "四要素校验通过");
        BaseLogUtils.info(logger, "getVerificationCodeYB", "江西金租获取易宝验证码 四要素信息： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));

        try{
            PrjCstAccInfoQueryCondition prjCstAccInfoQueryCondition = new PrjCstAccInfoQueryCondition();
            prjCstAccInfoQueryCondition.setPrjId(prjId);
            prjCstAccInfoQueryCondition.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfoQueryCondition.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_JXFL);
            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfoQueryCondition);
            // PrjCstAccInfoVO prjCstAccInfo = this.prjCstAccInfoService.selectByPrjId(prjId);
            BaseLogUtils.info(logger, "getVerificationCodeYB", "江西金租获取易宝验证码 项目基本信息： prjBscInfoVO = " + JSONObject.toJSONString(prjCstAccInfoVOS));
            if(CollectionUtils.isEmpty(prjCstAccInfoVOS)){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("请先保存项目客户信息");
                return result;
            }
            // 四要素验证
            PrjCstAccInfoVO prjCstAccInfoVO = prjCstAccInfoVOS.get(0);
            if(null == prjCstAccInfoVO.getChkRstCd() || Integer.valueOf(prjCstAccInfoVO.getChkRstCd()) != BaseConstant.IS_YESNO_YES) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("四要素信息有误，请修改");
                return result;
            }
            if (null == prjCstAccInfoVO.getBankCardTypeCd() || "1".equals(prjCstAccInfoVO.getBankCardTypeCd())){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("不支持此类银行卡，请更换为借记卡");
                return result;
            }
            // 发送验证码
            DataResultDTO dataResultDTO = this.jxflInsApiService.getVerificationCodeYB(String.valueOf(prjId));
            if(dataResultDTO!=null){
                if(BaseConstant.IS_YESNO_YES_NM.equals(dataResultDTO.getCode())){
                    result.setSuccess(BaseConstant.IS_YESNO_YES);
                    result.setInfo(dataResultDTO.getInfo());
                }else{
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo(dataResultDTO.getInfo());
                }
                result.setData(dataResultDTO.getData()); // rstCode
            }else{
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("易宝验证码获取失败，请重新尝试；");
            }
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.error(logger, "getVerificationCodeYB", "江西金租获取易宝验证码失败 " + ex.getMessage());
            ex.printStackTrace();
        }
        catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("获取易宝验证码失败!");
            BaseLogUtils.error(logger, "getVerificationCodeYB", "江西金租获取易宝验证码失败 " + ex.getMessage());
            ex.printStackTrace();
        }

        return result;
    }
    /**
     * 保存 项目客户信息。
     */
    @RequestMapping(value = "/save.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object save (Long prjId, PrjCstAccInfoQueryCondition prjCstAccInfoQC, HttpServletRequest request) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "四要素校验通过");
        BaseLogUtils.info(logger, "save", "江西金租立项保存 四要素信息： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));
        // 开户银行名称
        if(StringUtils.isBlank(prjCstAccInfoQC.getBkCd()) || StringUtils.isBlank(prjCstAccInfoQC.getBkNm())){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("请输入开户银行名称!");
            return result;
        }
        // 银行账号
        if(StringUtils.isBlank(prjCstAccInfoQC.getAccNo())){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("请输入银行账号!");
            return result;
        }
        // 手机号
        if(StringUtils.isBlank(prjCstAccInfoQC.getMp())){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("请输入手机号!");
            return result;
        }
        // 月收入
        if(StringUtils.isBlank(prjCstAccInfoQC.getMonthlyIncome())){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("请输入月收入!");
            return result;
        }
        // 家庭地址现居住地详细地址
        String homeAddr = request.getParameter("homeAddr");
        if (StringUtils.isBlank(homeAddr)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("请输入现居住地详细地址!");
            return result;
        }
        if (homeAddr.length() > 60) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("现居住地详细地址不得超过60字!");
            return result;
        }
        // 身份证地址-户籍地详细地址
        String idAddr = request.getParameter("idAddr");
        if (StringUtils.isBlank(idAddr)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("请输入户籍地详细地址!");
            return result;
        }
        if (idAddr.length() > 60) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("户籍地详细地址不得超过60字!");
            return result;
        }
        // 通讯地址
        String postAddr = request.getParameter("postAddr");
        if (StringUtils.isBlank(postAddr)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("请输入通讯地址!");
            return result;
        }
        if (postAddr.length() > 60) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("通讯地址不得超过60字!");
            return result;
        }
        // 证件有效起始日期
        String certValidSDt = request.getParameter("certValidSDt");
        if (StringUtils.isBlank(certValidSDt)) {
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护证件有效起始日期!");
        } else {
            if (!DateUtils.isDate(certValidSDt, "yyyy-MM-dd")) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护证件有效起始日期格式（yyyy-MM-dd）！");
            }
        }
        // 证件有效截止日期
        String certValidEDt = request.getParameter("certValidEDt");
        if (StringUtils.isBlank(certValidEDt)) {
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护证件有效终止日期!");
        } else {
            if ((!DateUtils.isDate(certValidEDt, "yyyy-MM-dd"))
                    &&(!certValidEDt.equals(PropertiesCacheUtils.getProperty(SystemConstant.CHECK_DATE_LONG)))) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护证件有效终止日期格式（yyyy-MM-dd 或 长期）！");
            }
        }
        if (!certValidEDt.equals(PropertiesCacheUtils.getProperty(SystemConstant.CHECK_DATE_LONG))) {
            Date startDate = DateUtils.formatStringToDate(certValidSDt, "yyyy-MM-dd");
            Date endDate = DateUtils.formatStringToDate(certValidEDt, "yyyy-MM-dd");
            if (DateUtils.equals(startDate, endDate) || DateUtils.after(endDate, startDate)) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "证件有效起始日期 不能大于等于 证件有效终止日期！");
            }
        }

        try{
            boolean cstFlag = false;
            // 修改自然人月收入
            CstNpBscInfoVO cstNpBscInfoVO = this.cstNpBscInfoService.selectById(prjCstAccInfoQC.getCstId());
            if(null != cstNpBscInfoVO) {
                Long mrIncMoney = DecimalUtils.convertYuanToFen(Double.valueOf(prjCstAccInfoQC.getMonthlyIncome())); // 月收入转为分
                Double yrInc = DecimalUtils.mul(mrIncMoney.doubleValue(),12d); // 月收入转换年收入
                boolean flag = false;
                if (!Objects.equals(cstNpBscInfoVO.getYrInc().doubleValue(), yrInc)) {
                    flag = true;
                    cstNpBscInfoVO.setYrInc(yrInc.longValue());
                }
                if (!Objects.equals(cstNpBscInfoVO.getHomeAddr(), homeAddr)) {
                    flag = true;
                    cstNpBscInfoVO.setHomeAddr(homeAddr);
                }
                if (!Objects.equals(cstNpBscInfoVO.getIdAddr(), idAddr)) {
                    flag = true;
                    cstNpBscInfoVO.setIdAddr(idAddr);
                }
                if (!Objects.equals(cstNpBscInfoVO.getPostAddr(), postAddr)) {
                    flag = true;
                    cstNpBscInfoVO.setPostAddr(postAddr);
                }
                if (!Objects.equals(cstNpBscInfoVO.getCertValidSDt(), certValidSDt)) {
                    flag = true;
                    cstNpBscInfoVO.setCertValidSDt(certValidSDt);
                }
                if (!Objects.equals(cstNpBscInfoVO.getCertValidEDt(), certValidEDt)) {
                    flag = true;
                    cstNpBscInfoVO.setCertValidEDt(certValidEDt);
                }
                if (flag) {
                    cstNpBscInfoVO.setMdfTm(new Date());
                    cstNpBscInfoVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
                    BaseLogUtils.info(logger, "save", "修改自然人信息 cstNpBscInfoVO"+ JSON.toJSONString(cstNpBscInfoVO), CurrentThreadContext.getCurrentUserName());
                    this.cstNpBscInfoService.modify(cstNpBscInfoVO);
                    cstFlag = true;
                }
            }
            PrjCstAccInfoQueryCondition prjCstAccInfoQueryCondition = new PrjCstAccInfoQueryCondition();
            prjCstAccInfoQueryCondition.setPrjId(prjId);
            prjCstAccInfoQueryCondition.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfoQueryCondition.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_JXFL);
            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfoQueryCondition);
            PrjCstAccInfoVO prjCstAccInfo = null;
            if(CollectionUtils.isNotEmpty(prjCstAccInfoVOS)){
                prjCstAccInfo = prjCstAccInfoVOS.get(0);
            }
            BaseLogUtils.info(logger, "save", "江西金租立项保存 项目基本信息： prjBscInfoVO = " + JSONObject.toJSONString(prjCstAccInfo));
            if(null != prjCstAccInfo && null != prjCstAccInfo.getId()){
                prjCstAccInfoQC.setId(prjCstAccInfo.getId());
                prjCstAccInfoQC.setChkRstCd(prjCstAccInfo.getChkRstCd());
                prjCstAccInfoQC.setAccResCd(prjCstAccInfo.getAccResCd());
                if (!(SysInsCfgInfoConstant.CODE_CST_AUTH_RST_CD_1.equals(prjCstAccInfo.getChkRstCd())
                        && ("2".equals(prjCstAccInfo.getAccResCd()) || "1".equals(prjCstAccInfo.getAccResCd())))) {
                    if (!(prjCstAccInfoQC.getCstNm().equals(prjCstAccInfo.getCstNm())
                            && prjCstAccInfoQC.getAccNo().equals(prjCstAccInfo.getAccNo())
                            && prjCstAccInfoQC.getMp().equals(prjCstAccInfo.getMp()))) {
                        // 四要素信息已修改，修改绑卡成功信息  0 ： 未绑卡 ； 1 ： 已绑定银联 ； 2 ： 全部绑卡成功 （必须先绑成功银联才能绑易宝）
                        prjCstAccInfoQC.setAccResCd("0"); // 0 : 都需要验证 ； 1：只易宝需要； 2:都不需要    （必须先绑成功银联才能绑易宝）
                    }
                }

            }
            // 四要素验证通过同时广州银联/易宝绑卡成功或同时绑卡成功后，江西金租信息采集页字段信息[账户类字段]不再允许修改
            if (!(SysInsCfgInfoConstant.CODE_CST_AUTH_RST_CD_1.equals(prjCstAccInfoQC.getChkRstCd())
                    && ("2".equals(prjCstAccInfoQC.getAccResCd()) || "1".equals(prjCstAccInfoQC.getAccResCd())))) {
                prjCstAccInfoQC.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_JXFL);
                // 保存项目客户信息，包含四要素验证
                prjCstAccInfoQC.setCertTypCd(DictionaryConstant.CODE_CERT_TYP_CD_0);
                prjCstAccInfoQC.setBkNo(prjCstAccInfoQC.getBkCd());
                BaseLogUtils.info(logger, "save", "江西金租立项保存 页面提交的项目客户信息： " + JSONObject.toJSONString(prjCstAccInfoQC));
                DataResultDTO resultDTO = this.prjCstAccInfoApiService.modifyPrjAccInfo(prjCstAccInfoQC);

                // 判断四要素校验结果
                BaseLogUtils.info(logger, "save", "江西金租立项保存 四要素验证结果 ： " + JSONObject.toJSONString(resultDTO));
                String chkRstCd = null, rstDesc = null;
                String bankCardType = null;
                Map<String, String> ckResMap = null;
                if(resultDTO != null && StringUtils.isNotEmpty(resultDTO.getCode())
                        && Integer.valueOf(resultDTO.getCode()) != BaseConstant.IS_YESNO_YES) {
                    chkRstCd = resultDTO.getCode();
                    rstDesc = resultDTO.getInfo();
                }else if(resultDTO != null && resultDTO.getData() != null) {
                    ckResMap = (Map<String, String>) resultDTO.getData();
                    chkRstCd = ckResMap.get("chkRstCd");
                    rstDesc = ckResMap.get("rstDesc");
                    bankCardType = ckResMap.get("bankCardType");
                }
                if(chkRstCd == null || Integer.valueOf(chkRstCd) != BaseConstant.IS_YESNO_YES) {
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo("四要素信息有误，请修改");
                    return result;
                }
                if ("1".equals(bankCardType)){
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo("不支持此类银行卡，请更换为借记卡");
                    return result;
                }
                result.setInfo("客户信息保存成功");
                result.setSuccess(BaseConstant.IS_YESNO_YES);
            } else {
                // 已符合：四要素验证通过同时广州银联/易宝绑卡成功或同时绑卡成功
                Map<String, String> data = new HashMap<>();
                data.put("chkRstCd", SysInsCfgInfoConstant.CODE_CST_AUTH_RST_CD_1);
                data.put("id", StringUtils.isNotEmpty(prjCstAccInfoQC.getId()) ? prjCstAccInfoQC.getId().toString() : "");
                result.setData(data);
                if (cstFlag) {
                    result.setSuccess(BaseConstant.IS_YESNO_YES);
                    data.put("rstDesc", "客户信息已保存");
                    result.setInfo("客户信息已保存");
                } else {
                    result.setSuccess(BaseConstant.IS_YESNO_YES);
                    data.put("rstDesc", "四要素验证/绑卡已通过");
                    result.setInfo("客户信息已保存");
                }
            }
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.error(logger, "save", "江西金租立项保存失败 " + ex.getMessage());
            ex.printStackTrace();
        }
        catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("保存失败!");
            BaseLogUtils.error(logger, "save", "江西金租立项保存失败 " + ex.getMessage());
            ex.printStackTrace();
        }
        BaseLogUtils.info(logger, "save", "江西金租签约绑卡end-result:" + result);
        return result;
    }

    /**
     * 广州银联绑卡
     */
    @RequestMapping(value = "/bindCardYL.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object bindCardYL (Long prjId, PrjCstAccInfoQueryCondition prjCstAccInfoQC) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "广州银联绑卡成功");
        BaseLogUtils.info(logger, "bindCardYL", "江西金租广州银联绑卡： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));
        try{
            PrjCstAccInfoQueryCondition prjCstAccInfoQueryCondition = new PrjCstAccInfoQueryCondition();
            prjCstAccInfoQueryCondition.setPrjId(prjId);
            prjCstAccInfoQueryCondition.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfoQueryCondition.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_JXFL);
            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfoQueryCondition);
            if(CollectionUtils.isEmpty(prjCstAccInfoVOS)){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("请先保存项目客户信息");
                return result;
            }
            PrjCstAccInfoVO prjCstAccInfo = prjCstAccInfoVOS.get(0);
            BaseLogUtils.info(logger, "bindCardYL", "江西金租广州银联绑卡： prjBscInfoVO = " + JSONObject.toJSONString(prjCstAccInfo));
            /**
             * 0 ： 未绑卡 ； 1 ： 已绑定银联 ； 2 ： 全部绑卡成功 （必须先绑成功银联才能绑易宝）
             */
            int needSignFlag = 0;
            if(StringUtils.isNotEmpty(prjCstAccInfo.getAccResCd())){
                needSignFlag = Integer.parseInt(prjCstAccInfo.getAccResCd());
            }
            BaseLogUtils.info(logger, "bindCardYL", "江西金租立项保存 项目基本信息： needSignFlag = " + needSignFlag);
            if(needSignFlag != 0){
                BaseLogUtils.info(logger, "signGZYL", "广州银联无需绑卡");
                return new DataResultVO(BaseConstant.IS_YESNO_YES, "广州银联无需绑卡");
            }
            if (needSignFlag == 0) {
                // 广州银联绑卡验证码
                if (StringUtils.isBlank(prjCstAccInfoQC.getGzylCode())) {
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "请输入广州银联绑卡验证码!");
                }
            }
            // 四要素验证
            if(null == prjCstAccInfo.getChkRstCd() || Integer.valueOf(prjCstAccInfo.getChkRstCd()) != BaseConstant.IS_YESNO_YES) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("四要素信息有误，请修改");
                return result;
            }
            if (null == prjCstAccInfo.getBankCardTypeCd() || "1".equals(prjCstAccInfo.getBankCardTypeCd())){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("不支持此类银行卡，请更换为借记卡");
                return result;
            }
            // 签约绑卡
            DataResultDTO dataResultDTO = this.jxflInsApiService.signGZYL(String.valueOf(prjId), prjCstAccInfoQC.getGzylCode());
            BaseLogUtils.info(logger, "bindCardYL", "江西金租签约绑卡 dataResultDTO:" + dataResultDTO);
            if(dataResultDTO!=null){
                if(BaseConstant.IS_YESNO_YES_NM.equals(dataResultDTO.getCode())) {//签约绑卡成功
                    result.setSuccess(BaseConstant.IS_YESNO_YES);
                    result.setInfo(dataResultDTO.getInfo());
                    //更新数据
                    // prjCstAccInfo.setAccResCd("1");
                    // BaseLogUtils.info(logger, "bindCardYL", "签约绑卡更新 项目客户账户信息End： prjCstAccInfo = " + JSONObject.toJSONString(prjCstAccInfo));
                    // boolean modify = this.prjCstAccInfoService.modify(prjCstAccInfo);
                    // BaseLogUtils.info(logger, "bindCardYL", "签约绑卡更新 项目客户账户信息End： modify = " + modify);
                }else{//签约绑卡失败
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo(dataResultDTO.getInfo());
                }
            }else{//签约绑卡失败
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("广州银联签约绑卡失败，请联系客户核实银行卡和预留手机号信息");
            }
            BaseLogUtils.info(logger, "bindCardYL", "江西金租广州银联签约绑卡 result:" + result);
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.error(logger, "bindCardYL", "江西金租广州银联签约绑卡失败 " + ex.getMessage());
            ex.printStackTrace();
        }
        catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("广州银联签约绑卡失败!");
            BaseLogUtils.error(logger, "bindCardYL", "江西金租广州银联签约绑卡失败 " + ex.getMessage());
            ex.printStackTrace();
        }
        BaseLogUtils.info(logger, "bindCardYL", "江西金租广州银联签约绑卡end-result:" + result);
        return result;
    }

    /**
     * 易宝绑卡
     */
    @RequestMapping(value = "/bindCardYB.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object bindCardYB (Long prjId, PrjCstAccInfoQueryCondition prjCstAccInfoQC) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "易宝绑卡成功");
        BaseLogUtils.info(logger, "bindCardYB", "江西金租易宝绑卡： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));
        try{
            PrjCstAccInfoQueryCondition prjCstAccInfoQueryCondition = new PrjCstAccInfoQueryCondition();
            prjCstAccInfoQueryCondition.setPrjId(prjId);
            prjCstAccInfoQueryCondition.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfoQueryCondition.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_JXFL);
            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfoQueryCondition);
            if(CollectionUtils.isEmpty(prjCstAccInfoVOS)){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("请先保存项目客户信息");
                return result;
            }
            PrjCstAccInfoVO prjCstAccInfo = prjCstAccInfoVOS.get(0);
            BaseLogUtils.info(logger, "bindCardYB", "江西金租易宝绑卡： prjBscInfoVO = " + JSONObject.toJSONString(prjCstAccInfo));
            /**
             * 0 ： 未绑卡 ； 1 ： 已绑定银联 ； 2 ： 全部绑卡成功 （必须先绑成功银联才能绑易宝）
             */
            int needSignFlag = 0;
            if(StringUtils.isNotEmpty(prjCstAccInfo.getAccResCd())){
                needSignFlag = Integer.parseInt(prjCstAccInfo.getAccResCd());
            }
            BaseLogUtils.info(logger, "bindCardYB", "江西金租立项保存 项目基本信息： needSignFlag = " + needSignFlag);
            if(needSignFlag == 2){
                BaseLogUtils.info(logger, "bindCardYB", "易宝无需绑卡");
                return new DataResultVO(BaseConstant.IS_YESNO_YES, "易宝无需绑卡");
            }
            if(needSignFlag == 0){
                BaseLogUtils.info(logger, "bindCardYB", "请先完成广州银联绑卡");
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请先完成广州银联绑卡");
            }
            if (needSignFlag == 1) {
                // 易宝绑卡验证码
                if (StringUtils.isBlank(prjCstAccInfoQC.getYbCode())) {
                    BaseLogUtils.info(logger, "bindCardYB", "请输入易宝绑卡验证码");
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "请输入易宝绑卡验证码!");
                }
            }
            // 四要素验证
            if(null == prjCstAccInfo.getChkRstCd() || Integer.valueOf(prjCstAccInfo.getChkRstCd()) != BaseConstant.IS_YESNO_YES) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("四要素信息有误，请修改");
                return result;
            }
            if (null == prjCstAccInfo.getBankCardTypeCd() || "1".equals(prjCstAccInfo.getBankCardTypeCd())){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("不支持此类银行卡，请更换为借记卡");
                return result;
            }
            // 签约绑卡
            DataResultDTO dataResultDTO = this.jxflInsApiService.signYB(String.valueOf(prjId), prjCstAccInfoQC.getYbCode());
            BaseLogUtils.info(logger, "bindCardYB", "江西金租签约绑卡 dataResultDTO:" + dataResultDTO);
            if(dataResultDTO!=null){
                if(BaseConstant.IS_YESNO_YES_NM.equals(dataResultDTO.getCode())) {//签约绑卡成功
                    result.setSuccess(BaseConstant.IS_YESNO_YES);
                    result.setInfo(dataResultDTO.getInfo());
                    //更新数据
                    // prjCstAccInfo.setAccResCd("2");
                    // BaseLogUtils.info(logger, "bindCardYB", "签约绑卡更新 项目客户账户信息End： prjCstAccInfo = " + JSONObject.toJSONString(prjCstAccInfo));
                    // boolean modify = this.prjCstAccInfoService.modify(prjCstAccInfo);
                    // BaseLogUtils.info(logger, "bindCardYB", "签约绑卡更新 项目客户账户信息End： modify = " + modify);
                }else{//签约绑卡失败
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo(dataResultDTO.getInfo());
                }
            }else{//签约绑卡失败
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("易宝绑卡失败，请联系客户核实银行卡和预留手机号信息");
            }
            BaseLogUtils.info(logger, "bindCardYB", "江西金租易宝绑卡 result:" + result);
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.error(logger, "bindCardYB", "江西金租易宝绑卡 " + ex.getMessage());
            ex.printStackTrace();
        }
        catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("易宝绑卡失败!");
            BaseLogUtils.error(logger, "bindCardYB", "江西金租易宝绑卡失败 " + ex.getMessage());
            ex.printStackTrace();
        }
        BaseLogUtils.info(logger, "bindCardYB", "江西金租易宝绑卡end-result:" + result);
        return result;
    }
}
